package de.koller.pulsar.scene.fog;

import de.koller.aframe.util.misc.ColorOperations;
import de.koller.aframe.util.resource.IOLoader;
import de.koller.oceanFramework.gl.util.RasterManager;
import de.koller.oceanFramework.math.RVec2;
import de.koller.pulsar.PNode;
import de.koller.pulsar.scene.IScene;
import java.util.Random;

public class FogScene extends PNode implements IScene {
	public final Random RND = new Random();
	public final int WIDTH = 1200, HEIGHT = 700;

	private RasterManager raster = new RasterManager( WIDTH, HEIGHT );		
	
	@Override
	protected void update( int elapsedTime ) {
		super.update( elapsedTime );
	
		raster.clear( 0xff000000 );
		
		RVec2[] lp = new RVec2[ 2 ];
		lp[0] = new RVec2( 650, 300 );
		lp[1] = new RVec2( 550, 400 );
		
		for( int x = 0; x < raster.getWidth(); x++ ) {
			for( int y = 0; y < raster.getHeight(); y++ ) {
				RVec2 v0 = RVec2.difference( new RVec2( lp[0].x, lp[0].y ), new RVec2( x, y ) ).normalize();
				RVec2 v1 = RVec2.difference( new RVec2( lp[1].x, lp[1].y ), new RVec2( x, y ) ).normalize();
				
				double r = RVec2.getAngle( v0, v1 );
				//if( Double.isNaN( r ) )
				//	r = Math.PI;
				
				double f = 1f / (Math.PI) * r;
				raster.setPixel( ColorOperations.setA( ColorOperations.mult( 0xffffffff, (float)f ), 0xff), x, y );
			}
			
			//System.out.println( x + " / " + raster.getWidth() );
		}
		
		proot.setSceneFrame( IOLoader.create( raster ) );
	}
	
}
